package me.mingshan.leetcode;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/destroying-asteroids/
 *
 * @author hanjuntao
 * @date 2025/6/5 0005
 */
public class L_2126_destroying_asteroids {
    public static void main(String[] args) {
        int[] asteroids = {3,9,19,5,21};
        System.out.println(asteroidsDestroyed(10, asteroids));
    }

    public static boolean asteroidsDestroyed(int mass, int[] asteroids) {
        Arrays.sort(asteroids);

        long s = mass;

        for (int i = 0; i < asteroids.length; i++) {
            if (s < asteroids[i]) {
                return false;
            }
            s += asteroids[i];
        }

        return true;
    }
}
